Crate minstant

source ·
Expand description

A drop-in replacement for std::time::Instant that measures time with high performance and high accuracy powered by TSC.

§Example

let start = minstant::Instant::now();

// Code snipppet to measure

let duration: std::time::Duration = start.elapsed();

§Platform Support

Currently, only the Linux on x86 or x86_64 is backed by TSC. On other platforms, minstant falls back to coarse time.

§Calibration

TSC doesn’t necessarily ticks in constant speed and even doesn’t synchronize across CPU cores. The calibration detects the TSC deviation and calculates the correction factors with the assistance of a source wall clock. Once the deviation is beyond a crazy threshold, the calibration will fail, and then we will fall back to coarse time.

This calibration is stored globally and reused. In order to start the calibration before any call to minstant as to make sure that the time spent on minstant is constant, we link the calibration into application’s initialization linker section, so it’ll get executed once the process starts.

See also the Instant type.

Structs§

  • An anchor which can be used to convert internal clocking counter into system timestamp.
  • Atomicatomic and target_has_atomic="64"
    Atomic variant of Instant.
  • A measurement of a monotonically nondecreasing clock. Similar to std::time::Instant but is faster and more accurate if TSC is available.

Functions§

  • Return true if the current platform supports TSC, and the calibration has succeed.